//
//  WangJiViewController.m
//  ShangChengMoBan
//
//  Created by yaoqi yaoqi on 16/9/13.
//  Copyright © 2016年 ping. All rights reserved.
//

#import "WangJiViewController.h"
#import "YanZhengMaBtn.h"
#import "ChongZhiViewController.h"
@interface WangJiViewController ()<UITextFieldDelegate,YanZhengMaBtnDelegate>
@property(nonatomic,strong)YanZhengMaBtn *huoQu;
@end

@implementation WangJiViewController
{
    UITextField * _shouJi;
    UITextField * _yanZheng;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self drawNavWithTitle:@"忘记密码" WithColor:[UIColor colorWithHue:0.00 saturation:0.00 brightness:1.00 alpha:1.00]];
    self.view.backgroundColor = [UIColor colorWithHue:0.69 saturation:0.02 brightness:0.96 alpha:1.00];
    [self drawBackButton];
    [self jieMian];
}
-(void)jieMian{
    UILabel * tit = [[UILabel alloc]initWithFrame:CGRectMake(10, 25+64, KScreenWidth-25, 20)];
    tit.text = @"请确保你的手机畅通,已接收验证码短信";
    tit.textColor = [UIColor grayColor];
    tit.font = [UIFont systemFontOfSize:14];
    [self.view addSubview:tit];
    UIView * view = [[UIView alloc]initWithFrame:CGRectMake(0, tit.bottom+5, KScreenWidth, 81)];
    view.layer.borderWidth = 1 ;
    view.layer.borderColor = [UIColor colorWithHue:0.71 saturation:0.02 brightness:0.87 alpha:1.00].CGColor;
    view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:view];
    _shouJi = [[UITextField alloc]initWithFrame:CGRectMake(15, 5, 150, 30)];
    _shouJi.placeholder = @"请输入用户名";
    _shouJi.delegate = self;
    _shouJi.font = [UIFont systemFontOfSize:13];
    [view addSubview:_shouJi];
    _huoQu = [[YanZhengMaBtn alloc]initWithFrame:CGRectMake(KScreenWidth-110,5,100, 30)];
    _huoQu.backgroundColor = [UIColor colorWithHue:0.00 saturation:0.93 brightness:1.00 alpha:1.00];
    _huoQu.DaoJiShitime = 60;
    _huoQu.delegate = self;
    _huoQu.layer.cornerRadius = 15;
    [_huoQu setTitle:@"发送验证码" forState:UIControlStateNormal];
    _huoQu.titleLabel.font = [UIFont systemFontOfSize:14];
    [view addSubview:_huoQu];
    UIView * view1 = [[UIView alloc]initWithFrame:CGRectMake(0, _huoQu.bottom+5, KScreenWidth, 1)];
    view1.backgroundColor = [UIColor colorWithHue:0.71 saturation:0.02 brightness:0.87 alpha:1.00];
    [view addSubview:view1];
    _yanZheng = [[UITextField alloc]initWithFrame:CGRectMake(15, view1.bottom+5, 150, 30)];
    _yanZheng.placeholder = @"请输入验证码";
    _yanZheng.font = [UIFont systemFontOfSize:13];
    _yanZheng.delegate = self;
    [view addSubview:_yanZheng];
    UIButton * xiaBu = [[UIButton alloc]initWithFrame:CGRectMake(20, view.bottom+8, KScreenWidth-40, 40)];
    [xiaBu setTitle:@"下一步" forState:UIControlStateNormal];
    xiaBu.titleLabel.font = [UIFont systemFontOfSize:14];
    xiaBu.backgroundColor = [UIColor colorWithHue:1.00 saturation:1.00 brightness:1.00 alpha:1.00];
    [xiaBu setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    xiaBu.layer.cornerRadius = 4;
    [xiaBu addTarget:self action:@selector(xiaBu) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:xiaBu];
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
    if([textField isEqual:_shouJi]){
        [_yanZheng becomeFirstResponder];
    }else{
       [textField endEditing:YES];
    }
    return YES;
}
-(void)xiaBu{
    if (_yanZheng.text.length == 0) {
        [[iToast makeText:@"  请输入验证码!  "] show];
    }else{
        ChongZhiViewController * chong = [[ChongZhiViewController alloc]init];
        chong.dic = [[NSMutableDictionary alloc]init];
        [chong.dic setValue:_shouJi.text forKey:@"userName"];
        [chong.dic setValue:_yanZheng.text forKey:@"trendsCode"];
        [self.navigationController pushViewController:chong animated:YES];

    }
 }
#pragma mark 获取验证码
-(void)sendYanZhengMa{
    
    [NetWorking NEWjieKouQingQiu:YZM_userZhaoHuiMiMaCode ANDIP:IP And:@{@"userName":_shouJi.text} anBlock:^(NSDictionary *dic, NSError *error) {
        NSLog(@"%@",dic[Response]);
        if (!error) {
            if ([[dic objectForKey:Code]integerValue] == 200) {
                [_huoQu daoJiShi];
                
             }
        }
    }];
    
}

@end
